package com.ftd.controller;

import com.ftd.exception.ApiException;
import com.ftd.util.DigestUtil;
import com.ftd.viewmodel.ApiResult;
import com.ftd.viewmodel.MapResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Peter on 2016-07-11.
 */
@RestController
public class LoginController extends BaseController {

    @RequestMapping(value = "login")
    public ApiResult login(String loginId, String password) {

        if (!"admin".equals(loginId)) {
            throw ApiException.unauthorized("用户名不存在");
        }

        if (!"666666".equals(password)) {
            throw ApiException.unauthorized("密码不正确");
        }

        MapResult mapResult = new MapResult();

        mapResult.put("token", DigestUtil.Encrypt("0:" + loginId));
        return mapResult;
    }


}
